package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.Constant;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.xml.UserXML;
import com.lzy.okhttputils.model.HttpParams;

/**
 * ================================================
 * 项目名称：bigdata
 * 类描述：购物车API
 * 包名：com.digitalchina.bigdata.api
 * 创建人：白彦东
 * 创建时间：2016/10/20 10:32
 * 修改备注：
 * ================================================
 */

public class BusinessCart {


    /**
     * 获取购物车列表
     *
     * @param activity
     * @param handler
     */
    public static void getShoppingCartItems(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_GET_SHOPPING_CART_ITEMS, "", params, handler,
                MSG.MSG_GET_SHOPPING_CART_ITEMS_SUCCESS, MSG.MSG_GET_SHOPPING_CART_ITEMS_FIELD);

    }

    /**
     * 商品加入购物车
     *
     * @param activity
     * @param itemId       商品Id
     * @param itemQuantity 商品数量(不需要商品数量的业务，传数值“1”)
     * @param supplierId   供应商id
     * @param poHandler
     */
    public static void addShoppingCartItem(Activity activity, String itemId, String itemQuantity, String itemPrice,
                                           String itemSummary, String supplierId, String supplierName, String supplierLogo,
                                           String supplierPhone, String supplierAddress, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));
        params.put("itemId", itemId);
        params.put("itemQuantity", itemQuantity);
        params.put("itemPrice", itemPrice);
        params.put("itemSummary", itemSummary);
        params.put("supplierId", supplierId);
        params.put("supplierName", supplierName);
        params.put("supplierLogo", supplierLogo);
        params.put("supplierPhone", supplierPhone);
        params.put("supplierAddress", supplierAddress);
        params.put("appChannel", Constant.APP_CHANNEL); // 应用渠道 PC：0，移动端：1

        OkHttpUtil.post(activity, URL.URL_ADD_SHOPPING_CART_ITEM, "请稍候...", params, poHandler, MSG.MSG_ADD_SHOPPING_CART_ITEM_SUCCESS, MSG.MSG_ADD_SHOPPING_CART_ITEM_FIELD);

    }


    /**
     * 获取购物车中的商品数量
     *
     * @param activity
     * @param poHandler
     */
    public static void getShoppingCartItemCount(Activity activity, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_GET_SHOPPING_CART_ITEM_COUNT, "", params, poHandler, MSG.MSG_GET_SHOPPING_CART_ITEM_COUNT_SUCCESS, MSG.MSG_GET_SHOPPING_CART_ITEM_COUNT_FIELD);

    }


    /**
     * 获取购物车中的商品总额 (未使用 - 目前使用本地计算)
     *
     * @param activity
     * @param poHandler
     */
    public static void getShoppingCartItemAmount(Activity activity, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_GET_SHOPPING_CART_ITEM_AMOUNT, "", params, poHandler, MSG.MSG_GET_SHOPPING_CART_ITEM_AMOUNT_SUCCESS, MSG.MSG_GET_SHOPPING_CART_ITEM_AMOUNT_FIELD);

    }

    /**
     * 获取购物车中的运费总额 (未使用 - 移动端购物车不显示运费)
     *
     * @param activity
     * @param poHandler
     */
    public static void getShoppingCartItemPostage(Activity activity, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_GET_SHOPPING_CART_ITEM_POSTAGE, "", params, poHandler, MSG.MSG_GET_SHOPPING_CART_ITEM_POSTAGE_SUCCESS, MSG.MSG_GET_SHOPPING_CART_ITEM_POSTAGE_FIELD);

    }

    /**
     * 删除一组（或多组）商品
     *
     * @param activity
     * @param items     一组购物项id，之间用逗号分隔
     * @param poHandler
     */
    public static void removeShoppingCartItemList(Activity activity, String items, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("items", items);

        OkHttpUtil.post(activity, URL.URL_REMOVE_SHOPPING_CART_ITEM_LIST, "", params, poHandler, MSG.MSG_REMOVE_SHOPPING_CART_ITEM_LIST_SUCCESS, MSG.MSG_REMOVE_SHOPPING_CART_ITEM_LIST_FIELD);

    }

    /**
     * 删除一个商品
     *
     * @param activity
     * @param shoppingCartItemId -购物项id
     * @param poHandler
     */
    public static void removeShoppingCartItem(Activity activity, String shoppingCartItemId, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("shoppingCartItemId", shoppingCartItemId);

        OkHttpUtil.post(activity, URL.URL_REMOVE_SHOPPING_CART_ITEM, "", params, poHandler, MSG.MSG_REMOVE_SHOPPING_CART_ITEM_SUCCESS, MSG.MSG_REMOVE_SHOPPING_CART_ITEM_FIELD);

    }

    /**
     * 删除指定的商品（订单结算时的回调）
     *
     * @param activity
     * @param orderNos  一组订单号，之间用逗号分隔
     * @param poHandler
     */
    public static void removeShoppingByOrderNos(Activity activity, String orderNos, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("useraccid", UserXML.getUserId(activity));
        params.put("orderNos", orderNos);

        OkHttpUtil.post(activity, URL.URL_REMOVE_SHOPPING_BYORDERNOS, "", params, poHandler, MSG.MSG_REMOVE_SHOPPING_BYORDERNOS_SUCCESS, MSG.MSG_REMOVE_SHOPPING_BYORDERNOS_FIELD);

    }

    /**
     * 清空失效的商品（已下架、已作废）
     *
     * @param activity
     * @param poHandler
     */
    public static void clearInvalidShoppingCartItems(Activity activity, Handler poHandler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_CLEAR_INVALID_ITEMS, "请稍候...", params, poHandler,
                MSG.MSG_CLEAR_INVALID_ITEMS_SUCCESS, MSG.MSG_CLEAR_INVALID_ITEMS_FIELD);

    }


}
